package com.neusoft.neuiotms.dcom.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.ServiceLevelDTO;
import com.neusoft.neuiotms.dcom.model.ServiceLevel;
import com.neusoft.neuiotms.dcom.repository.ServiceLevelRepository;

@Component
public class ServiceLevelConverter extends AbstractConverter<ServiceLevel, ServiceLevelDTO> {

    @Autowired
    private ServiceLevelRepository serviceLevelRepository;

    @Override
    public ServiceLevel toModel(final ServiceLevelDTO dto) {
        ServiceLevel model;

        if (dto.isNew()) {
            model = new ServiceLevel();
        } else {
            model = this.serviceLevelRepository.getOne(dto.getId());
        }
        model.setContent(dto.getContent());
        model.setReadingVolume(dto.getReadingVolume());
        model.setTitle(dto.getTitle());
        model.setUpdateTime(dto.getUpdateTime());
        model.setUpdateUserCode(dto.getUpdateUserCode());
        model.setUpdateUserName(dto.getUpdateUserName());
        model.setUserCode(dto.getUserCode());
        model.setUserName(dto.getUserName());
        model.setAttachment(dto.getAttachment());
        model.setKeywords(dto.getKeywords());
        //附件
        return model;
    }

    @Override
    public ServiceLevelDTO toDTO(final ServiceLevel model, final boolean forListView) {
        final ServiceLevelDTO dto = new ServiceLevelDTO();

        dto.setContent(model.getContent());
        dto.setCreateTime(model.getCreateTime());
        dto.setId(model.getId());
        dto.setReadingVolume(model.getReadingVolume());
        dto.setTitle(model.getTitle());
        dto.setUpdateTime(model.getUpdateTime());
        dto.setUpdateUserCode(model.getUpdateUserCode());
        dto.setUpdateUserName(model.getUpdateUserName());
        dto.setUserCode(model.getUserCode());
        dto.setUserName(model.getUserName());
        dto.setAttachment(model.getAttachment());
        dto.setKeywords(model.getKeywords());
        return dto;
    }

}
